home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 September / Australian PC User - September 2003 (CD1).iso / magstuff / web / files / psp801ev.exe / Data1.cab / prod_tour.swf / scripts / %3Cdefault package%3E / CollapseMenuSymbol.as < prev    next >
Encoding:
Text File  |  2003-06-06  |  8.1 KB  |  236 lines

  1. function CollapseMenu()
  2. {
  3.    this.createEmptyMovieClip("collapseMenu_mc",5);
  4.    this.parentDepth = 10;
  5.    this.parentSettings = {unpressedcolor:11141120,hoverunpressedcolor:16711680,pressedcolor:52224,hoverpressedcolor:65280};
  6.    this.parentItems = new Array();
  7.    this.childSettings = {unpressedcolor:11141120,hoverunpressedcolor:16711680,pressedcolor:52224,hoverpressedcolor:65280};
  8.    this.mainSettings = {expansionDurationInFrames:6,h:300,w:400};
  9.    this.childItems = new Object();
  10.    this.currHeight = 0;
  11.    this.scrollToCurrChildAfterExpand = false;
  12.    this.child_tf = new TextFormat();
  13.    this.child_labelX = 26;
  14.    this.child_labelY = 0;
  15.    this.child_labelW = 105;
  16.    this.child_labelH = 19;
  17.    this.child_tf.font = "childEmbedFont";
  18.    this.child_tf.size = 11;
  19. }
  20. CollapseMenu.prototype = new MovieClip();
  21. Object.registerClass("CollapseMenuSymbol",CollapseMenu);
  22. CollapseMenu.prototype.init = function(xmlSetupStr, theChildNodeCallBack)
  23. {
  24.    var menuXML = new XML(xmlSetupStr);
  25.    if(menuXML.status == 0)
  26.    {
  27.       var cn = menuXML.firstChild;
  28.       while(cn)
  29.       {
  30.          if(cn.nodeName == "mainSettings")
  31.          {
  32.             this.mainSettings.expansionDurationInFrames = cn.attributes.expansionDurationInFrames;
  33.             this.mainSettings.h = cn.attributes.h;
  34.             this.mainSettings.w = cn.attributes.w;
  35.          }
  36.          else if(cn.nodeName == "parentSettings")
  37.          {
  38.             this.parentSettings.unpressedcolor = cn.attributes.unpressedcolor;
  39.             this.parentSettings.hoverunpressedcolor = cn.attributes.hoverunpressedcolor;
  40.             this.parentSettings.pressedcolor = cn.attributes.pressedcolor;
  41.             this.parentSettings.hoverpressedcolor = cn.attributes.hoverpressedcolor;
  42.          }
  43.          else if(cn.nodeName == "childSettings")
  44.          {
  45.             this.childSettings.unpressedcolor = cn.attributes.unpressedcolor;
  46.             this.childSettings.hoverunpressedcolor = cn.attributes.hoverunpressedcolor;
  47.             this.childSettings.pressedcolor = cn.attributes.pressedcolor;
  48.             this.childSettings.hoverpressedcolor = cn.attributes.hoverpressedcolor;
  49.             if(cn.attributes.labelX != null)
  50.             {
  51.                this.child_labelX = cn.attributes.labelX;
  52.             }
  53.             if(cn.attributes.labelY != null)
  54.             {
  55.                this.child_labelY = cn.attributes.labelY;
  56.             }
  57.             if(cn.attributes.labelW != null)
  58.             {
  59.                this.child_labelW = cn.attributes.labelW;
  60.             }
  61.             if(cn.attributes.labelH != null)
  62.             {
  63.                this.child_labelH = cn.attributes.labelH;
  64.             }
  65.             if(cn.attributes.fontsize != null)
  66.             {
  67.                this.child_tf.size = cn.attributes.fontsize;
  68.             }
  69.          }
  70.          else if(cn.nodeName == "parent")
  71.          {
  72.             var cp = this.createParentItem(cn,this.currHeight);
  73.             this.currHeight += cp.childContainer_mc._y + 4;
  74.          }
  75.          cn = cn.nextSibling;
  76.       }
  77.    }
  78.    this.collapseMenu_mc.controller = this;
  79.    this.collapseMenu_mc.getWidth = function()
  80.    {
  81.       return this._width;
  82.    };
  83.    this.collapseMenu_mc.getHeight = function()
  84.    {
  85.       return this.controller.currHeight;
  86.    };
  87.    this.attachMovie("FScrollPaneSymbol","sp_mc",2);
  88.    this.sp_mc.controller = this;
  89.    this.sp_mc.addProperty("contentHeight",this.getCurrHeight,null);
  90.    this.sp_mc.setSize(this.mainSettings.w,this.mainSettings.h);
  91.    this.sp_mc.setScrollContent(this.collapseMenu_mc);
  92.    this.childNodeCallBack = theChildNodeCallBack;
  93. };
  94. CollapseMenu.prototype.getCurrHeight = function()
  95. {
  96.    return this.controller.currHeight;
  97. };
  98. CollapseMenu.prototype.createParentItem = function(parentNode, initialY)
  99. {
  100.    var depth = this.parentDepth + this.parentItems.length;
  101.    this.collapseMenu_mc.attachMovie("ParentItemSymbol","p" + depth,depth);
  102.    this.collapseMenu_mc["p" + depth]._y = initialY;
  103.    this.collapseMenu_mc["p" + depth].controller = this;
  104.    this.parentItems.push(this.collapseMenu_mc["p" + depth]);
  105.    this.collapseMenu_mc["p" + depth].init(parentNode);
  106.    this.collapseMenu_mc["p" + depth].index = this.parentItems.length - 1;
  107.    return this.collapseMenu_mc["p" + depth];
  108. };
  109. CollapseMenu.prototype.parentItemClicked = function(parentItem)
  110. {
  111.    this.ignoreClicks = true;
  112.    this.delta = parentItem.childrenHeight;
  113.    this.dir = !parentItem.isExpanded ? 1 : -1;
  114.    this.currHeight -= this.dir * this.delta;
  115.    this.currFrame = 1;
  116.    this.howLong = parentItem.expansionDurationInFrames == null ? this.mainSettings.expansionDurationInFrames : parentItem.expansionDurationInFrames;
  117.    this.affectedParent = parentItem;
  118.    this.parentStartIndex = parentItem.index + 1;
  119.    this.onEnterFrame = function()
  120.    {
  121.       if(this.currFrame <= this.howLong)
  122.       {
  123.          var i = this.parentStartIndex;
  124.          while(i < this.parentItems.length)
  125.          {
  126.             if(this.currFrame == 1)
  127.             {
  128.                this.parentItems[i].startY = this.parentItems[i]._y;
  129.             }
  130.             var cf = this.currFrame;
  131.             this.parentItems[i]._y = this.dir * this.delta * (cf /= this.howLong) * (cf - 2) + this.parentItems[i].startY;
  132.             i++;
  133.          }
  134.          this.affectedParent.exposeChildren(this.currFrame,this.howLong,this.dir);
  135.          this.currFrame = this.currFrame + 1;
  136.       }
  137.       else
  138.       {
  139.          var i = this.parentStartIndex;
  140.          while(i < this.parentItems.length)
  141.          {
  142.             this.parentItems[i]._y = this.parentItems[i].startY - this.dir * this.delta;
  143.             i++;
  144.          }
  145.          this.ignoreClicks = false;
  146.          this.affectedParent.updateState();
  147.          this.sp_mc.refreshPane();
  148.          this.sp_mc.refreshPane();
  149.          if(this.scrollToCurrChildAfterExpand)
  150.          {
  151.             this.scrollToCurrChildAfterExpand = false;
  152.             this.scrollCurrChildIntoView();
  153.          }
  154.          else
  155.          {
  156.             delete this.onEnterFrame;
  157.          }
  158.       }
  159.    };
  160. };
  161. CollapseMenu.prototype.childItemClicked = function(childItem)
  162. {
  163.    if(this.currChild)
  164.    {
  165.       this.currChild.unClick();
  166.    }
  167.    this.currChild = childItem;
  168.    this.childNodeCallBack(this.currChild);
  169. };
  170. CollapseMenu.prototype.selectItem = function(itemName)
  171. {
  172.    var c = this.childItems[itemName];
  173.    if(c != null)
  174.    {
  175.       if(this.currChild != c)
  176.       {
  177.          this.currChild.unClick();
  178.          this.currChild = c;
  179.          this.currChild.showAsPressed();
  180.       }
  181.       trace(this.currChild.parentItem._target);
  182.       if(this.currChild.parentItem.isExpanded)
  183.       {
  184.          this.scrollCurrChildIntoView();
  185.       }
  186.       else
  187.       {
  188.          this.scrollToCurrChildAfterExpand = true;
  189.          this.currChild.parentItem.doPress();
  190.       }
  191.    }
  192.    return c;
  193. };
  194. CollapseMenu.prototype.scrollCurrChildIntoView = function()
  195. {
  196.    var p = {x:this.currChild._x,y:this.currChild._y};
  197.    this.currChild._parent.localToGlobal(p);
  198.    this.globalToLocal(p);
  199.    var delta = 0;
  200.    if(p.y < this.sp_mc._y)
  201.    {
  202.       delta = this.sp_mc._y - p.y;
  203.    }
  204.    else if(p.y + this.currChild._height > this.sp_mc._y + this.sp_mc._height)
  205.    {
  206.       delta = this.sp_mc._y + this.sp_mc._height - (p.y + 2 * this.currChild._height);
  207.    }
  208.    if(delta != 0)
  209.    {
  210.       this.ignoreClicks = true;
  211.       this.delta = delta;
  212.       this.sp_mc.startY = this.sp_mc.getScrollPosition().y;
  213.       this.currFrame = 1;
  214.       this.howLong = Math.floor(this.delta / 40);
  215.       if(this.howLong < 2)
  216.       {
  217.          this.howLong = 2;
  218.       }
  219.       this.onEnterFrame = function()
  220.       {
  221.          if(this.currFrame <= this.howLong)
  222.          {
  223.             var cf = this.currFrame;
  224.             this.sp_mc.setScrollPosition(0,this.delta * (cf /= this.howLong) * (cf - 2) + this.sp_mc.startY);
  225.             this.currFrame = this.currFrame + 1;
  226.          }
  227.          else
  228.          {
  229.             this.parentItems[i]._y = this.delta + this.collapseMenu_mc.startY;
  230.             this.ignoreClicks = false;
  231.             delete this.onEnterFrame;
  232.          }
  233.       };
  234.    }
  235. };
  236.